const path = require('path')
const { VueLoaderPlugin } = require('vue-loader')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
  mode: 'development', // production / development
  entry: path.join(__dirname, 'src/main.js'),
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        use: 'vue-loader',
      },
      {
        test: /\.css|scss$/,
        use: ['vue-style-loader', 'css-loader', 'sass-loader'],
      },
      {
        test: /\.(png|jpe?g|gif)$/i,
        use: [
          {
            loader: 'file-loader',
          },
        ],
      },
      {
        test: /\.(png|jpg|gif)$/i,
        use: [
          {
            loader: 'url-loader',
            options: {
              // 图片的大小限制
              limit: 8192, // 将这个大小以下的图片，打包成一个base64字符的图片，减少静态资源请求，提升项目性能
            },
          },
        ],
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: 'public/index.html',
    }),
    new VueLoaderPlugin(),
  ],
  devServer: {
    port: 8080,
    open: true,
    // compress: true,
    // 接口代理（解决跨域问题）
    proxy: {
      // '/api': 'http://localhost:3000/list',
      // http://localhost:3000/api/list
      '/api': {
        target: 'http://localhost:3000',
        // changeOrigin: true, //  改变源路径，http://localhost:3000/api/list
        pathRewrite: {
          // 重写路径
          '^/api': '',
        },
      },
    },
  },
  //  别名
  resolve: {
    // @ -> src
    alias: {
      '@': path.resolve('src'),
    },
  },
}
